package com.atguigu.lease.admin.controller.apartment;

import com.atguigu.lease.admin.service.RoomInfoService;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.bean.RoomInfo;
import com.atguigu.lease.model.vo.RoomDetailVo;
import com.atguigu.lease.model.vo.RoomItemVo;
import com.atguigu.lease.model.vo.RoomQueryVo;
import com.atguigu.lease.model.vo.RoomSubmitVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "房间信息管理模块")
@RestController
@RequestMapping("/admin/room")
public class RoomController {
    @Autowired
    RoomInfoService roomInfoService;
    ///admin/room/listBasicByApartmentId?id=10
    @Operation(summary = "4、根据公寓id查询可用的房间列表")
    @GetMapping("listBasicByApartmentId")
    public Result listBasicByApartmentId(@RequestParam("id") Long apartmentId) {
        // 查询房间表 + 租约表，查询可用的房间列表
        List<RoomInfo> roomInfos = roomInfoService.listBasicByApartmentId(apartmentId);
        return Result.ok(roomInfos);
    }
    @Operation(summary = "3、根据id查询房间详情")
    @GetMapping("getDetailById")
    public Result<RoomDetailVo> getDetailById(@RequestParam(value = "id", required = true) Long id) {
        return Result.ok(roomInfoService.getDetailById(id));
    }

    @Operation(summary = "2、带条件分页查询房间列表")
    @GetMapping("pageItem")
    public Result<Page<RoomItemVo>> pageItem(@RequestParam Long current, @RequestParam Long size,
                                             RoomQueryVo queryVo) {
        // 再编写分页查询的业务+自定义sql
//        roomInfoService.pageItem(current,size,queryVo);
        /*
        # 一个房间对应一个公寓，一个房间对应一个有效租约

        select t1.*
            , t2.*
            ,t3.lease_end_date , if(t3.id is null , false , true) AS isCheckIn , t3.`status`
        from room_info t1
        left join apartment_info t2
        on t1.apartment_id = t2.id and t2.is_deleted = 0
        left join lease_agreement t3
        on t1.id = t3.room_id and t3.is_deleted = 0 and t3.status in(2,5)
        where t1.is_deleted = 0 ;


         */
        return Result.ok();
    }
    @Operation(summary = "1、新增或更新房间")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody RoomSubmitVo roomSubmitVo) {
        roomInfoService.saveOrUpdateRoomSubmitVo(roomSubmitVo);
        return Result.ok();
    }
}
